home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Form / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  9.7 KB  |  361 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Form.hpp"
  11.  
  12. #ifndef PART_H
  13. #include "Part.h"
  14. #endif
  15.  
  16. #ifndef CONTENT_H
  17. #include "Content.h"
  18. #endif
  19.  
  20. #ifndef FRAME_H
  21. #include "Frame.h"
  22. #endif
  23.  
  24. #ifndef DIALOG_H
  25. #include "Dialog.h"
  26. #endif
  27.  
  28. #ifndef VIEW_H
  29. #include "View.h"
  30. #endif
  31.  
  32. #ifndef SCROLLED_H
  33. #include "ScrollEd.h"
  34. #endif
  35.  
  36. #ifndef BINDING_K
  37. #include "Binding.k"
  38. #endif
  39.  
  40. // ----- Framework Layer -----
  41.  
  42. #ifndef FWABOUT_H
  43. #include "FWAbout.h"
  44. #endif
  45.  
  46. #ifndef FWUTIL_H
  47. #include "FWUtil.h"
  48. #endif
  49.  
  50. #ifndef FWITERS_H
  51. #include "FWIters.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWSCLBAR_H
  59. #include "FWSclBar.h"
  60. #endif
  61.  
  62. #ifndef FWKIND_H
  63. #include "FWKind.h"
  64. #endif
  65.  
  66. #ifndef FWINCVW_H
  67. #include "FWIncVw.h"
  68. #endif
  69.  
  70. // ----- OS Layer -----
  71.  
  72. #ifndef FWMENU_H
  73. #include "FWMenu.h"
  74. #endif
  75.  
  76. #ifndef FWCFMRES_H
  77. #include "FWCFMRes.h"
  78. #endif
  79.  
  80. #ifndef FWRESTYP_H
  81. #include "FWResTyp.h"
  82. #endif
  83.  
  84. #ifndef FWSUSINK_H
  85. #include "FWSUSink.h"
  86. #endif
  87.  
  88. #ifndef FWEVENT_H
  89. #include "FWEvent.h"
  90. #endif
  91.  
  92. #ifndef FWPICSHP_H
  93. #include "FWPicShp.h"
  94. #endif
  95.  
  96. #ifndef SLMixOS_H
  97. #include "SLMixOS.h"
  98. #endif
  99.  
  100. // ----- Foundation Layer -----
  101.  
  102. #ifndef FWSTREAM_H
  103. #include "FWStream.h"
  104. #endif
  105.  
  106. #ifndef FWSTRS_H
  107. #include "FWStrs.h"
  108. #endif
  109.  
  110. // ----- OpenDoc Includes -----
  111.  
  112. #ifndef SOM_Module_OpenDoc_StdProps_defined
  113. #include <StdProps.xh>
  114. #endif
  115.  
  116. // ----- PPob View Support -----
  117.  
  118. #if FW_PPOB_VIEWS
  119. #include "FWPPobRd.h"
  120. #endif
  121.  
  122. //========================================================================================
  123. //    Runtime info
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfform
  128. #endif
  129.  
  130. FW_DEFINE_AUTO(CFormPart)
  131.  
  132. //========================================================================================
  133. //    CFormPart class
  134. //========================================================================================
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // CFormPart constructor
  138. //----------------------------------------------------------------------------------------
  139.  
  140. CFormPart::CFormPart(ODPart* odPart) :
  141.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  142.     fTextData(""),
  143.     fIsForm(TRUE),
  144.     fMainPresentation(NULL),
  145.     fPwdDialogPresentation(NULL)
  146. {
  147.     FW_END_CONSTRUCTOR
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. // CFormPart destructor
  152. //----------------------------------------------------------------------------------------
  153.  
  154. CFormPart::~CFormPart()
  155. {
  156.     FW_START_DESTRUCTOR
  157. }
  158.  
  159. //----------------------------------------------------------------------------------------
  160. // CFormPart::Initialize
  161. //----------------------------------------------------------------------------------------
  162.  
  163. void CFormPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)    // Override
  164. {
  165.     FW_CPart::Initialize(ev, storageUnit, fromStorage);
  166.  
  167.     // ----- Register our Presentations
  168.     //    By not passing a view id for fMainPresentation we force ODF to call our frame's
  169.     //  CreateSubView method.
  170. #if FW_ODFRC_VIEWS
  171.     fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, kEmbeddedFormView, kRootFormView);
  172.     fPrintPresentation = RegisterPresentation(ev, kPrintPresentation, FALSE, kPrintFormView, kPrintFormView);
  173.     fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE,
  174.                                                 kPasswordDialog, kPasswordDialog, NULL);
  175. #else
  176.     fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, NULL);
  177.     fPrintPresentation = RegisterPresentation(ev, kPrintPresentation, FALSE, NULL);
  178.     fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE, NULL);
  179. #endif
  180.     
  181.     // ----- Register one extra kind -----
  182.     // This seems to fix a problem with enabling Paste in the 
  183.     // custom text field. It may not be the right thing to do.
  184.     RegisterKind(ev, 'TEXT', kODPlatformDataType, FW_kDataInterchangeStorage, FW_kImportExportEnabled);
  185.     
  186.     //
  187.     // Make sure that classes created from PPob resources 
  188.     // won't be dead-stripped!
  189.     //
  190.     
  191. #if FW_PPOB_VIEWS
  192.     FW_CPPobReader::RegisterAllPPClasses();
  193.     FW_CPPobReader::RegisterClass('Frmv', ReadFormView);
  194.     FW_CPPobReader::RegisterClass('PwEd', ReadPasswordEditView);
  195.     FW_CPPobReader::RegisterClass('ScEd', ReadScrollingEdit);
  196. #endif
  197.     
  198.     //
  199.     // Make sure that classes created from ODFRC resources 
  200.     // won't be dead-stripped!
  201.     // 
  202.     
  203. #if FW_ODFRC_VIEWS
  204.     FW_DO_NOT_DEAD_STRIP(CFormView);
  205.     /*NEW*/ FW_DO_NOT_DEAD_STRIP(FW_CGraphicControl);
  206.     FW_DO_NOT_DEAD_STRIP(FW_CIncludeView);
  207.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  208.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
  209.     FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
  210.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
  211.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  212.     FW_DO_NOT_DEAD_STRIP(FW_CListBox);
  213.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  214.     FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
  215.     FW_DO_NOT_DEAD_STRIP(FW_CPopupMenu);
  216. #endif
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    CFormPart::NewPartContent
  221. //----------------------------------------------------------------------------------------
  222. //    ODF Method
  223.  
  224. FW_CContent* CFormPart::NewPartContent(Environment* ev)
  225. {
  226.     return (FW_NEW(CFormContent, (ev, this)));
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. // CFormPart::NewFrame
  231. //----------------------------------------------------------------------------------------
  232.  
  233. FW_CFrame* CFormPart::NewFrame(Environment* ev,
  234.                                 ODFrame* odFrame,
  235.                                 FW_CPresentation* presentation,
  236.                                 FW_Boolean fromStorage)    // Override
  237. {
  238.     FW_UNUSED(fromStorage);
  239.     FW_CFrame* newFrame = NULL;
  240.  
  241.     if (presentation == fMainPresentation || presentation == fPrintPresentation) {
  242.         // Create the frame for the main presentation
  243.         newFrame = FW_NEW(CFormFrame, (ev, odFrame, presentation, this));
  244.     }
  245.     else if (presentation == fPwdDialogPresentation) {
  246.         // Create the frame for the dialog presentation, using an ODFRC resource id
  247.         newFrame = FW_NEW(CPwdDialogFrame, (ev, odFrame, presentation, this));
  248.     }
  249.     
  250.     return newFrame;
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. // CFormPart::DoMenu
  255. //----------------------------------------------------------------------------------------
  256.  
  257. FW_Handled CFormPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  258. {
  259.     FW_Handled menuHandled = FW_kHandled;
  260.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  261.     
  262.     switch (id)
  263.     {
  264.         case cResetFormCommand:
  265.             DoFormCommand(ev);
  266.             break;
  267.         
  268. #if FW_PPOB_VIEWS  && defined(FW_DEBUG)
  269.         case cReloadPPobViews:
  270.             // Reload the views from an external resource file. 
  271.             FW_CFrame* frame = GetLastActiveFrame(ev);
  272.             CFormFrame* formFrame = FW_DYNAMIC_CAST(CFormFrame, frame);
  273.             if (formFrame)
  274.                 FW_CPPobReader::RecreateViews (ev, kRootFormView, formFrame, formFrame);
  275.             break;
  276. #endif
  277.         default:
  278.             menuHandled = FW_kNotHandled;
  279.     }
  280.  
  281.     return menuHandled;
  282. }
  283.  
  284. //----------------------------------------------------------------------------------------
  285. //    CFormPart::DoAbout
  286. //----------------------------------------------------------------------------------------
  287.  
  288. FW_Handled CFormPart::DoAbout(Environment* ev)
  289. {
  290.     ::FW_About(ev, this, kAbout);
  291.     
  292.     return FW_kHandled;
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. // CFormPart::DoAdjustMenus
  297. //----------------------------------------------------------------------------------------
  298.  
  299. FW_Handled CFormPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  300.                                      FW_Boolean hasMenuFocus,
  301.                                      FW_Boolean isRoot)    // Override
  302. {
  303. FW_UNUSED(isRoot);
  304.     if (hasMenuFocus)
  305.     {    
  306.         // ToDo: should enable command only if the form has changed
  307.         menuBar->EnableCommand(ev, cResetFormCommand, true);
  308. #if FW_PPOB_VIEWS  && defined(FW_DEBUG)
  309.         menuBar->EnableCommand(ev, cReloadPPobViews, true);
  310. #endif
  311.     }
  312.     return FW_kNotHandled;
  313. }
  314.  
  315. //----------------------------------------------------------------------------------------
  316. // CFormPart::DoFormCommand
  317. //----------------------------------------------------------------------------------------
  318.  
  319. void CFormPart::DoFormCommand(Environment* ev)
  320. {
  321.     // This sample doesn't use a Content model yet. For now the "reset" command will 
  322.     // simply erase the text in the edit-fields of each frame
  323.     
  324.     FW_CPresentationFrameIterator iter(ev, fMainPresentation);
  325.     for (CFormFrame* frame = (CFormFrame*)iter.First(ev); iter.IsNotComplete(ev); frame = (CFormFrame*)iter.Next(ev))
  326.     {
  327.         CFormView* formView = (CFormView*) frame->GetContentView(ev);
  328.         formView->ResetData(ev);                
  329.     }
  330.  
  331. #if 0
  332.     // [LSD] PartMaker-generated code, not used yet because we don't have a content model
  333.         
  334.     // Mark the document as changed so it can be saved
  335.     Changed(ev);
  336.  
  337.     // Mark the display frame as changed, so that containing parts can update links
  338.     fMainPresentation->ContentUpdated(ev);
  339.  
  340.     // Force all frames to be redrawn
  341.     fMainPresentation->Invalidate(ev);
  342. #endif
  343. }
  344.  
  345. //----------------------------------------------------------------------------------------
  346. // CFormPart::GetResourceString
  347. //----------------------------------------------------------------------------------------
  348.  
  349. void CFormPart::GetResourceString(Environment* ev,
  350.                                   FW_ResourceID multiStringID,
  351.                                   FW_ResourceID stringID,
  352.                                   FW_CString& string)
  353. {
  354.     // ----- Open the resource file for this shared library -----
  355.     FW_PSharedLibraryResourceFile resFile(ev);
  356.  
  357.     // ----- Read the string from the resource file -----
  358.     ::FW_LoadStringByID(ev, resFile, multiStringID, FW_kMultiStringRes, stringID, string);
  359. }
  360.  
  361.